﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using Qianwei.Model;
using Qianwei.Biz;
using Qianwei.Common;

namespace Qianwei.Web.Master
{
    public partial class Default : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetMenu();
            }
        }

        private void SetMenu()
        {
            StringBuilder strFirstMenu = new StringBuilder();
            StringBuilder strSecondMenu = new StringBuilder();
            int count = 1;
            IList<menu_info> menulist = MenuInfoManager.Instance.QueryMenuInfo(null);
            var firstMenu = menulist.Where(s => s.Depth == 1);
            strFirstMenu.Append("<ul>");
            foreach (var first in firstMenu)
            {
                strFirstMenu.AppendFormat("<li><a id=\"mm{0}\" onmouseover=\"showM(this,{0});\" onmouseout=\"OnMouseLeft();\" href=\"{1}\" target=\"_parent\">{2}</a></li>",
                    count, first.Page_Url, first.Menu_Name);
                var childs = menulist.Where(s => s.Parent_Id == first.Menu_Id);
                strSecondMenu.AppendFormat("<ul class=\"hide\" id=\"mb{0}\">", count);
                foreach (var child in childs)
                {
                    strSecondMenu.AppendFormat("<li><a href=\"{0}\" target=\"_parent\">{1}</a></li>",
                        child.Page_Url, child.Menu_Name);
                }
                strSecondMenu.Append("</ul>");
                count++;
            }
            strFirstMenu.Append("</ul>");

            lmainmenu_top.Text = strFirstMenu.ToString();
            lmainmenu_rbg.Text = strSecondMenu.ToString();
            //Util.PageAlert(lmainmenu_top.Text);
        }
    }
}